<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数组</title>
    <script>
      let users = ["dong", "xixi", "nan"];

      // 访问数组元素
      console.log(users[2]);

      // 修改数组元素
      users[1] = "dd";
      console.log(users[1]);

      // 数组长度
      console.log(users.length);

      // 遍历数组
      // 方式一
      for (let i = 0; i < users.length; i++) {
        console.log(users[i]);
      }
      // 方式二
      for (eve in user) {
        console.log(eve);
      }

      // 末尾添加元素
      let newLength = users.push("xixi");
      console.log(newLength);
      console.log(users);

      // 末尾删除元素
      let removedItem = users.pop();
      console.log(removedItem);

      // 开始添加元素
      users.unshift("xiaoming");
      console.log(users);

      // 开始删除元素
      users.shift();
      console.log(users);
    </script>
  </head>
  <body></body>
</html>
